package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseFile;
import com.briup.mt.bean.BaseFileExample;
import com.briup.mt.dao.BaseFileMapper;
import com.briup.mt.service.IBaseFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class BaseFileSeiviceImpl implements IBaseFileService {
    @Autowired
    private BaseFileMapper baseFileMapper;

    @Override
    public List<BaseFile> query(String file_name, String group_name) {
        BaseFileExample example=new BaseFileExample();
        if (!StringUtils.isEmpty(file_name)){
            example.createCriteria().andFileNameLike("%"+file_name+"%");
        }
        if(!StringUtils.isEmpty(group_name)){
            example.createCriteria().andGroupNameEqualTo(group_name);
        }

        List<BaseFile> list = baseFileMapper.selectByExample(example);
        return list;
    }
    @Override
    public void saveOrUpdate(BaseFile baseFile) {
        if(baseFile.getId() == null){
            // 初始化操作
            baseFile.setId(new Date().getTime()+"");
            baseFileMapper.insert(baseFile);
        } else {
            baseFileMapper.updateByPrimaryKey(baseFile);
        }
    }

    @Override
    public void deleteById(String id) {
           baseFileMapper.deleteByPrimaryKey(id);
    }
}
